package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.*;
import com.atguigu.gmall.product.service.ManageService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.log4j.Log4j;
import org.apache.ibatis.annotations.Options;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @Author: 孙润达
 * @Date: 2022/1/2 12:13
 */
//@CrossOrigin已配置网关此注释要注释掉
@RestController
@RequestMapping("/admin/product")
@Api(value = "查询分类")
public class ManageController {
    @Autowired
    private ManageService manageService;

    @ApiOperation("获取一级标题getCategory1")
    @GetMapping("/getCategory1")
    public Result getCategory1(){
      List<BaseCategory1>  baseCategory1s=manageService.getCategory1();
      return Result.ok(baseCategory1s);
    }

    @ApiOperation("获取二级标题getCategory2")
    @GetMapping("/getCategory2/{Category1Id}")
    public Result getCategory2(@PathVariable Long  Category1Id){
      List<BaseCategory2>  baseCategory2s=manageService.getCategory2(Category1Id);
      return Result.ok(baseCategory2s);
    }

    @ApiOperation("获取三级标题getCategory3")
    @GetMapping("/getCategory3/{Category2Id}")
    public Result getCategory3(@PathVariable Long  Category2Id){
      List<BaseCategory3>  baseCategory3s=manageService.getCategory3(Category2Id);
      return Result.ok(baseCategory3s);
    }

    @ApiOperation("根据多级标题获取详细内容")
    ///admin/product/attrInfoList/1/1/1
    @GetMapping("/attrInfoList/{Category1Id}/{Category2Id}/{Category3Id}")
    public Result attrInfoList(@PathVariable Long  Category1Id,
                                 @PathVariable Long  Category2Id,
                                 @PathVariable Long  Category3Id){
      List<BaseAttrInfo>  baseAttrInfos=manageService.attrInfoList(Category1Id,Category2Id,Category3Id);
      return Result.ok(baseAttrInfos);
    }

    @ApiOperation("添加平台属性")
    @PostMapping("/saveAttrInfo")
    public Result saveAttrInfo(@RequestBody BaseAttrInfo baseAttrInfo){
        manageService.saveAttrInfo(baseAttrInfo);
        return  Result.ok();
    }
    @ApiOperation("修改平台属性（回显数据）")
    @GetMapping("/getAttrValueList/{attrId}")
    public Result getAttrValueList(@PathVariable Long attrId){
    List<BaseAttrValue> baseAttrValue=  manageService.getAttrValueList(attrId);
        return  Result.ok(baseAttrValue);
    }
    @ApiOperation("分页查询")
    @GetMapping("/baseTrademark/{page}/{limit}")
    public Result baseTrademark(@PathVariable Integer page,
                                @PathVariable Integer limit){
        IPage  iPage =manageService.baseTrademark(page,limit);
        return Result.ok(iPage);
    }
    @ApiOperation("添加品牌")
    @PostMapping("/baseTrademark/save")
    public Result baseTrademarkSave(@RequestBody BaseTrademark baseTrademark){
        manageService.baseTrademarkSave(baseTrademark);
        return Result.ok();
    }

    @ApiOperation("删除品牌")
    @DeleteMapping("/baseTrademark/remove/{baseTrademarkId}")
    public Result remove(@PathVariable Long baseTrademarkId){
        manageService.remove(baseTrademarkId);
        return  Result.ok();
    }

    @ApiOperation("查询单个品牌（修改品牌用于回显数据）")
    @GetMapping("/baseTrademark/get/{baseTrademarkId}")
    public Result getByIdBaseTrademark(@PathVariable Long baseTrademarkId){
        BaseTrademark baseTrademark=  manageService.getByIdBaseTrademark(baseTrademarkId);
        return  Result.ok(baseTrademark);
    }

    @ApiOperation("保存单个品牌（修改品牌）")
    @PutMapping("/baseTrademark/update")
    public Result update(@RequestBody BaseTrademark baseTrademark){
         manageService.update(baseTrademark);
        return  Result.ok();
    }

    @ApiOperation("spu分页查询")
    @GetMapping("/{page}/{limit}")
    public Result spuInfo(@PathVariable Integer page,
                          @PathVariable Integer limit,
                           Long category3Id){
      IPage iPage= manageService.spuInfo(page,limit,category3Id);
      return  Result.ok(iPage);
    }


    @ApiOperation("获取品牌属性值")
    @GetMapping("/baseTrademark/getTrademarkList")
    public  Result  getTrademarkList(){
        List<BaseTrademark> baseTrademark= manageService.getTrademarkList();
        return Result.ok(baseTrademark);
    }

    @ApiOperation("获取销售属性值")
    @GetMapping("/baseSaleAttrList")
    public  Result  baseSaleAttrList(){
        List<BaseSaleAttr> baseSaleAttrList= manageService.baseSaleAttrList();
        return Result.ok(baseSaleAttrList);
    }

    @ApiOperation("保存spu内容")
    @PostMapping("/saveSpuInfo")
    public  Result  saveSpuInfo(@RequestBody SpuInfo spuInfo){
        manageService.saveSpuInfo(spuInfo);
        return Result.ok();
    }

    @ApiOperation("根据spuId获取图片列表")
    @GetMapping("/spuImageList/{spuId}")
    public Result spuImageList(@PathVariable Long spuId){
       List<SpuImage> spuImageList= manageService.spuImageList(spuId);
       return Result.ok(spuImageList);
    }
    @ApiOperation("根据spuId获取销售属性")
    @GetMapping("/spuSaleAttrList/{spuId}")
    public Result spuSaleAttrList(@PathVariable Long spuId){
     List<SpuSaleAttr>  spuSaleAttrList=  manageService.spuSaleAttrList(spuId);
     return Result.ok(spuSaleAttrList);
    }

    @ApiOperation("添加sku")
    @PostMapping("/saveSkuInfo")
    public Result saveSkuInfo(@RequestBody SkuInfo skuInfo){
        manageService.saveSkuInfo(skuInfo);
     return Result.ok();
    }
    @ApiOperation("分页查询sku")
    @GetMapping("/list/{page}/{limit}")
    public Result list(@PathVariable Integer page,
                       @PathVariable Integer limit){
      IPage<SkuInfo> iPage= manageService.list(page,limit);
     return Result.ok(iPage);
    }
    @ApiOperation("sku上架")
    @PutMapping("/onSale/{skuId}")
    public Result onSale(@PathVariable Long skuId){
      manageService.onSale(skuId);
     return Result.ok();
    }
    @ApiOperation("sku下架")
    @PutMapping("/cancelSale/{skuId}")
    public Result cancelSale(@PathVariable Long skuId){
      manageService.cancelSale(skuId);
     return Result.ok();
    }

}
